﻿@using LeadMaster.Helpers
@using LeadMaster.Properties
@using LeadMaster.Controllers;
@model LeadMaster.ViewModels.ViewModelClient

<style type="text/css">
.InfoRowHeight
{
    height: 20px;   
}
.sectionheader
{
    font-size: 9px;
    text-align: left;
 {
 }
 .topsectiontitles
    text-align: left;
    background-color: #BFFFFF;
 }
</style>

<div class="spacer"></div>

<table>
<tr class="InfoRowHeight">
<td rowspan="6"><img src="~/Images/Dunsmore.png" style="width: 120px; height: 120px" /></td>
<td colspan="3">&nbsp;</td>
</tr>
<tr class="InfoRowHeight">
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="InfoRowHeight">
<td><label>Client</label></td>
<td><label style="font-weight:bold; color: #000000;">@Model.Leads.IntRef.Trim()</label></td>
<td><label>CONFIDENTIALITY NOTICE</label></td>
</tr>
<tr class="InfoRowHeight">
<td><label>Total Leads</label></td>
<td><label style="font-weight:bold; color: #000000;">
@ViewBag.TotalLeads
</label></td>
<td><label>This Lead information is Confidential, Exclusive and for the intended addressee only under Non-Disclosure Agreement and may be legally privileged and protected by law.</label></td>
</tr>
<tr>
<td><label>&nbsp;</label></td>
<td>
<label style="font-weight:bold; color: #000000;">
&nbsp;
</label>
</td>
<td><label>Please note Days Left To Return and action as soon as possilbe. Legal professional privilege may apply and is not waived for  unintended recipients.</label></td>
</tr>
<tr class="InfoRowHeight">
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
@if (@Model.FullListLeadResults != null && @Model.FullListLeadResults.Count() > 0)
{
<div class="spacer"></div>
<table style="width:3500px;">
<tr>
@for (int i = 0; i < @Model.GridTitlesList.Count(); i++)
{
    <th>
    <label style="color: #FF0000; font-size: 9px; font-family: Arial, Helvetica, sans-serif; font-weight: bold;">
    @if (Model.FullListLeadResults[i].LeadResult.LeadGroupQuestion != null && Model.FullListLeadResults[i].LeadResult.LeadGroupQuestionsID > 0)
    {
        if (Model.FullListLeadResults[i].LeadResult.LeadGroupQuestion.ClientNote != null)
        {
            @Model.FullListLeadResults[i].LeadResult.LeadGroupQuestion.ClientNote
        }
    }
    </label>
    </th>    
}
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</tr>

<tr>
@{
int colSpan = 1;
string blockTitle = "";
string backColour="";
for (int i = 0; i < @Model.GridTitlesList.Count(); i++)
{
    if (Model.FullListLeadResults[i].LeadResult.LeadStatQuestion != null && Model.FullListLeadResults[i].LeadResult.LeadStatQuestionsID > 0)
    {
        if (blockTitle == Model.FullListLeadResults[i].LeadResult.LeadStatQuestion.LeadStat.Title)
        {
            colSpan++;
            
        }
        else
        {
            if (blockTitle.Trim().Length > 0)
            {
                <th colspan="@(colSpan)" class="topsectiontitles" style="background-color: #@(backColour);"><label class="sectionheader">@blockTitle</label></th>                    
            }
            colSpan = 1;
            backColour = Model.GridTitlesList[i].Backcolour;
            blockTitle = Model.FullListLeadResults[i].LeadResult.LeadStatQuestion.LeadStat.Title;
        }
    }
    if (Model.FullListLeadResults[i].LeadResult.LeadGroupQuestion != null && Model.FullListLeadResults[i].LeadResult.LeadGroupQuestionsID > 0)
    {
        if (blockTitle == Model.FullListLeadResults[i].LeadResult.LeadGroupQuestion.LeadGroups.Title)
        {
            colSpan++;
        }
        else
        {
            if (blockTitle.Trim().Length > 0)
            {
                <th colspan="@(colSpan)" class="topsectiontitles" style="background-color: #@(backColour);"><label class="sectionheader">@blockTitle</label></th>                
            }
            colSpan = 1;
            backColour = Model.GridTitlesList[i].Backcolour;
            blockTitle = Model.FullListLeadResults[i].LeadResult.LeadGroupQuestion.LeadGroups.Title;
        }
    }
    if (Model.FullListLeadResults[i].LeadResult.CompanyRegisteredID != null && Model.FullListLeadResults[i].LeadResult.CompanyRegisteredID > 0)
    {
        if (blockTitle == "Registration")
        {
            colSpan++;
        }
        else
        {
            if (blockTitle.Trim().Length > 0)
            {
                <th colspan="@(colSpan)" class="topsectiontitles"><label class="sectionheader">@blockTitle</label></th>
            }
            colSpan = 1;
            blockTitle = "Registration";
        }
    }
    if (Model.FullListLeadResults[i].LeadResult.CompanyRestrictionsID != null && Model.FullListLeadResults[i].LeadResult.CompanyRestrictionsID > 0)
    {
        if (blockTitle == "Restriction")
        {
            colSpan++;
        }
        else
        {
            if (blockTitle.Trim().Length > 0)
            {
            <th colspan="@(colSpan)" class="topsectiontitles"><label class="sectionheader">@blockTitle</label></th>
            }
            colSpan = 1;
            blockTitle = "Restriction";
        }
    }
    if (Model.FullListLeadResults[i].LeadResult.CompanySundriesID != null && Model.FullListLeadResults[i].LeadResult.CompanySundriesID > 0)
    {
        if (blockTitle == "Sundries")
        {
            colSpan++;
        }
        else
        {
            if (blockTitle.Trim().Length > 0)
            {
            <th colspan="@(colSpan)" class="topsectiontitles"><label class="sectionheader">@blockTitle</label></th>
            }
            colSpan = 1;
            blockTitle = "Sundries";
        }
    }
} 
<th colspan="@(colSpan)" class="topsectiontitles" style="background-color: #@(backColour);"><label class="sectionheader">@blockTitle</label></th>
}
<th style="background-color: #BFBFBF;">&nbsp;</th>
<th style="background-color: #BFBFBF;">&nbsp;</th>
<th style="background-color: #BFBFBF;">&nbsp;</th>
<th style="background-color: #BFBFBF;">&nbsp;</th>
<th style="background-color: #BFBFBF;">&nbsp;</th>
<th style="background-color: #BFBFBF;">&nbsp;</th>
<th style="background-color: #BFBFBF;">&nbsp;</th>
</tr>
<tr>
@for (int i = 0; i < @Model.GridTitlesList.Count(); i++)
{
    <th style="background-color: #@(Model.GridTitlesList[i].Backcolour); ">
    <label style="color: #FF0000;">
    @if (Model.FullListLeadResults[i].LeadResult.LeadStatQuestion != null && Model.FullListLeadResults[i].LeadResult.LeadStatQuestionsID > 0)
    {
        if (Model.FullListLeadResults[i].LeadResult.LeadStatQuestion.Mandatory == true)
        {
            @:M
        }
        else
        {
            @:I
        }
    }
    @if (Model.FullListLeadResults[i].LeadResult.LeadGroupQuestion != null && Model.FullListLeadResults[i].LeadResult.LeadGroupQuestionsID > 0)
    {
        if (Model.FullListLeadResults[i].LeadResult.LeadGroupQuestion.Mandatory == true)
        {
            @:M
        }
        else
        {
            @:I
        }
    }
    @if (Model.FullListLeadResults[i].LeadResult.CompanyRegisteredID != null && Model.FullListLeadResults[i].LeadResult.CompanyRegisteredID > 0)
    {
        if (Model.FullListLeadResults[i].LeadResult.CompanyRegistered.MandatoryLeadQuestion == true)
        {
            @:M
        }
        else
        {
            @:I
        }
    }
    @if (Model.FullListLeadResults[i].LeadResult.CompanyRestrictionsID != null && Model.FullListLeadResults[i].LeadResult.CompanyRestrictionsID > 0)
    {
        if (Model.FullListLeadResults[i].LeadResult.CompanyRestriction.MandatoryLeadQuestion == true)
        {
            @:M
        }
        else
        {
            @:I
        }
    }    
    @if (Model.FullListLeadResults[i].LeadResult.CompanySundriesID != null && Model.FullListLeadResults[i].LeadResult.CompanySundriesID > 0)
    {
        if (Model.FullListLeadResults[i].LeadResult.CompanySundry.MandatoryLeadQuestion == true)
        {
            @:M
        }
        else
        {
            @:I
        }
    }    
    </label>
    </th>    
}
<th style="background-color: #BFBFBF;">&nbsp;</th>
<th style="background-color: #BFBFBF;">&nbsp;</th>
<th style="background-color: #BFBFBF;">&nbsp;</th>
<th style="background-color: #BFBFBF;">&nbsp;</th>
<th style="background-color: #BFBFBF;">&nbsp;</th>
<th style="background-color: #BFBFBF;">&nbsp;</th>
<th style="background-color: #BFBFBF;">&nbsp;</th>
</tr>
<tr>
@for (int i = 0; i < @Model.GridTitlesList.Count(); i++)
{
    <th style="border: 1px solid #000000; background-color: #BFBFBF;">
    <label style="color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; font-size: 10px;">
    @Model.GridTitlesList[i].Title
    </label>
    </th>    
}
<th style="border: 1px solid #000000; background-color: #BFBFBF;">
<label style="color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; font-size: 10px;">
Purchase Order
</label>
</th>
<th style="border: 1px solid #000000; background-color: #BFBFBF;">
<label style="color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; font-size: 10px;">
New or Replacement  
</label>
</th>
<th style="border: 1px solid #000000; background-color: #BFBFBF;">
<label style="color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; font-size: 10px;">
Days Left To Return
</label>
</th>
<th style="border: 1px solid #000000; background-color: #BFBFBF;">
<label style="color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; font-size: 10px;">
Current Status
</label>
</th>
<th style="border: 1px solid #000000; background-color: #BFBFBF;">
<label style="color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; font-size: 10px;">
Your Return Reason
</label>
</th>
<th style="border: 1px solid #000000; background-color: #BFBFBF; width:200px; !important">
<label style="color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; font-size: 10px;">
Dunsmore Findings
</label>
</th>
<th style="border: 1px solid #000000; background-color: #BFBFBF; width:200px; !important">
<label style="color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; font-size: 10px;">
Your Own Notes
</label>
</th>
</tr>
<tr style="@(ClientController.GetColourCode(Model.FullListLeadResults.FirstOrDefault().LeadFlag.LeadFlagsID))">
@{
int iCounter = 0;
int daysDiff = 0;
bool firstRow = true;
string colourCode = ClientController.GetColourCode(Model.FullListLeadResults.FirstOrDefault().LeadFlag.LeadFlagsID);
foreach (var item in Model.FullListLeadResults)
{
    daysDiff = (item.LeadStatus.Lead.ReturnDays ?? 6);
    daysDiff += AdditionalDays.AddLeadDays(Convert.ToDateTime(item.LeadStatus.LeadDate).DayOfWeek);
    daysDiff -= (Convert.ToInt16((DateTime.Now - (Convert.ToDateTime(item.LeadStatus.LeadDate))).TotalDays));
    daysDiff = daysDiff < 0 ? 0 : daysDiff;
    if (firstRow == false && iCounter == 0)
    {
        colourCode = ClientController.GetColourCode(item.LeadFlag.LeadFlagsID);        
    @: style="@(colourCode)">

    }
    <td style="border: 1px solid #000000;">
    <label style="font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; @(colourCode)"             
    @if(daysDiff==1 && (item.LeadFlag.LeadFlagsID==2 || item.LeadFlag.LeadFlagsID==6) && (item.Lockdown==null || item.Lockdown==false))
    {
        @:class="blinker"   
    }
    >
    @item.LeadResult.Answer
    </label>
    </td>
    iCounter++;
    if (iCounter == item.LeadResult.QuestionBlock)
    {
        <text>
            <td style="border: 1px solid #000000; background-color: #bfbfbf; color: #f6f3e8;" >
            <input type="hidden" name="LeadDate" value="@(item.LeadStatus.LeadDate)" />
            <label id="pid@(item.LeadResult.LeadResultsID)" style="color: #000000; font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold;" data-id="@(item.LeadResult.LeadResultsID)">
            @if (item.LeadStatus.PurchaseOrder != null)
            {
                @item.LeadStatus.PurchaseOrder.PID
            }
            else
            {
             @:&nbsp;   
            }
            </label>
			@if (this.User.IsInRole(ApplicationRoles.Operations) && item.LeadStatus.PurchaseOrder == null)
   {
			<input type="button" id="btnPID@(item.LeadResult.LeadResultsID)" data-leadstatusid="@(item.LeadStatus.LeadStatusID)" class="btnemptypid" value="Assign PO" />
   }
            </td>
            <td style="border: 1px solid #000000; background-color: #bfbfbf; color: #f6f3e8;" >
            <label style="color: #000000; font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold;"  data-id="@(item.LeadResult.LeadResultsID)"
            @if(daysDiff<2 && item.Lockdown==null)
            {
             @:class="blinker"   
            }
            >
            @if (item.LeadStatus.Replacement != null)
            {
                @item.LeadStatus.Replacement.ToString().Replace("True", "Replacement")
            }
            else
            {
                @:New
            }
            </label>
            </td>
            <td style="border: 1px solid #000000; background-color: #bfbfbf; color: #f6f3e8;" >
            <label style="color: #000000; font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold;" data-id="@(item.LeadResult.LeadResultsID)"
            @if(daysDiff<2 && item.Lockdown==null)
            {
             @:class="blinker"   
            }            
            >
            @daysDiff
            </label>
            </td>
            <td style="border: 1px solid #000000;" >
            @if (daysDiff > 0)
            {
            <label 
            @if (item.Lockdown != true)
            {
            @:style="color: #000000; font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; cursor: pointer;"  class="changeleadstatus" 
            }
            else
            {
            @:style="color: ##a49a8f; font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold;" 
            }
            data-id="@(item.LeadResult.LeadResultsID)" id="flag_@(item.LeadStatus.LeadID)_@(item.LeadStatus.BlockID)">@item.LeadFlag.Description</label>
            }
            else
            {
                if (item.LeadFlag.LeadFlagsID == 2 && item.LeadReason.LeadReasonsID == 1)
                {
                <label>Lead Accepted</label> 
                }
                else if (item.LeadFlag.LeadFlagsID == 2 && item.LeadReason.LeadReasonsID > 1)
                {
                <label>Lead Accepted - Reason Given But Lead Not Rejected</label> 
                }
                else 
                {
                <label>@item.LeadFlag.Description</label>    
                }
            }
            @if (item.Lockdown != true && 1==2)
            {
            <br />
            <input type="button" value="Escalate" id="btnEscalate@(item.LeadStatus.LeadStatusID)" data-id="@(item.LeadStatus.LeadStatusID)" />   
            }
            </td>
            <td style="border: 1px solid #000000;">
            @if (daysDiff > 0)
            {
                <label 
                @if (item.Lockdown != true && (item.LeadFlag.LeadFlagsID==8 || item.LeadFlag.LeadFlagsID==6))
                {
                @:style="color: #000000; font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; cursor: pointer;" class="changeleadreason" 
                }
                else
                {
                @:style="color: ##a49a8f; font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold;"     
                }
                    data-id="@(item.LeadResult.LeadResultsID)" id="reas_@(item.LeadStatus.LeadID)_@(item.LeadStatus.BlockID)">
                @if (item.LeadFlag.LeadFlagsID==8 && item.LeadReason.LeadReasonsID!=1)
                {
                @item.LeadReason.Description
                }
                @if (item.LeadStatus.Manfield != null && item.LeadStatus.Manfield != "0")
                {
                 @item.LeadStatus.Manfield   
                }
                </label>                
            }
            else
            {
                <label>@item.LeadReason.Description</label>
            }
            </td>
            <td style="border: 1px solid #000000;">
            <textarea id="note_@(item.LeadStatus.LeadID)_@(item.LeadStatus.BlockID)" 
            @if(item.LeadStatus.Notes!=null)
            {
            @:class="clientnotes"
            }
            >@item.LeadStatus.Notes</textarea>
            </td>
            <td style="border: 1px solid #000000; width:200px; !important">
<textarea rows="4" columns="200" style="color: #000000; font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; cursor: pointer; width:200px; !important" class="changeclientnotes 
            @if(item.LeadStatus.Notes!=null)
            {
            @:clientnotes
            }
            " data-id="@(item.LeadStatus.LeadStatusID)">
@if (item.LeadStatus.ClientNotes != null)
{
@item.LeadStatus.ClientNotes;
}
</textarea>
            </td>
            <td>
            <a href="http://webellas.arvixevps.com/ReportServer_SQLEXPRESS/Pages/ReportViewer.aspx?%2forac%2fAdministrator%2fdunsmore%2fClientWorkSheet&rs:Command=Render&leadid=@(item.LeadResult.LeadID)&blockid=@(item.LeadResult.BlockId)&rc:Parameters=false" target="_blank">
             <img src="~/Images/workplan.png" style="height:25px; width: 25px;"/>
            </a>
            </td>
			@if (@item.LeadFlag.LeadFlagsID == 6 && @item.LeadStatus.VoxFile != null)
            {
			<td>
            @if(item.LeadStatus.VoxFile.Substring(item.LeadStatus.VoxFile.Length-3,3).Equals("mp3"))
            {
                <audio controls>
                <source src="@Url.Action("PlayVoxFile")/?voxFile=@(Server.UrlEncode(item.LeadStatus.VoxFile))" type="audio/mp3" />
                </audio>
            }
            else if(item.LeadStatus.VoxFile.Substring(item.LeadStatus.VoxFile.Length-3,3).ToUpper().Equals("WAV"))
            {
                <audio id="audio1" controls preload="auto" autobuffer src="@Url.Action("PlayVoxFile")/?voxFile=@(Server.UrlEncode(item.LeadStatus.VoxFile))" type="audio/vnd.wav">
                </audio>
                <label style="font-family: 'Trebuchet MS'; font-size: 8px; color: #808080">If your media player (above) cant play the file, please install the Apple plug-in to hear the voice files.</label>
                <object>
                <param name="src" value="@Url.Action("PlayVoxFile")/?voxFile=@(Server.UrlEncode(item.LeadStatus.VoxFile))" />
                <param name="controller" value="true" />
                <embed src="~/Vox/@(item.LeadStatus.VoxFile)" type="audio/wav" />
                </object>
                
            }
            else
            {
				<p>Your browser does not support HTML 5 audio element</p>
            }
			</td>
            }
            @if (item.LeadStatus.Lead.StreetView == true)
            {
            <td>
            <a style='font-family: Arial, Helvetica, sans-serif; font-size: 9px; font-style: italic; color: #800080' 
                href='https://www.google.co.uk/maps/place/@(QCController.StreetviewLatLong(item.LeadStatus.LeadStatusID))' target='_blank'>Lat/Long </a>
            <a style='font-family: Arial, Helvetica, sans-serif; font-size: 9px; font-style: italic; color: #800080' href='https://www.google.co.uk/maps/place/@(QCController.StreetviewPostcode(item.LeadStatus.LeadStatusID))' target='_blank'>Postcode</a>
            </td>
            }
        </text>
        @:</tr><tr
        if (firstRow == true)
        {
            firstRow = false;
        }
        iCounter = 0;
    }
}
}
></tr>
</table>
}
else
{
<h3>No Leads have been entered yet.</h3>
}
<div id="changestatus"></div>
<div id="changereason"></div>
<div id="escalate"></div>
<input type="hidden" id="selectedelement" value="" />

<script type="text/javascript">
    $(document).ready(function () {

        runEffect();

          function runEffect() {
          // get effect type from
          var selectedEffect = "shake";
 
          // most effect types need no options passed by default
          var options = {};
          // some effects have required parameters
          if ( selectedEffect === "scale" ) {
            options = { percent: 0 };
          } else if ( selectedEffect === "transfer" ) {
            options = { to: "#button", className: "ui-effects-transfer" };
          } else if ( selectedEffect === "size" ) {
            options = { to: { width: 200, height: 60 } };
          }
 
          // run the effect
          $( ".blinker" ).effect( selectedEffect, options, 500, callback );
        };

        function callback() {
            setTimeout(function() {
                $( ".blinker" ).removeAttr( "style" ).hide().fadeIn();
            }, 1000 );
        };

        $("escalate").dialog({
            autoOpen: false,
            width: 600,
            open: function () { $(".ui-dialog").css("box-shadow", "#000 5px 5px 5px"); },
            position: ['middle', 20],
            modal: true,
            dialogClass: 'notitle',
            buttons: {
                Send: function () {
                    $(this).dialog("close");
                    $("#formEscalate").submit();
                    $($("#selectedelement").val()).toggle();
                },
                cancel: function () {
                    $(this).dialog("close");
                }
            }
        });


        $("#changestatus").dialog(
        {
            autoOpen: false,
            width: 600,
            open: function () { $(".ui-dialog").css("box-shadow", "#000 5px 5px 5px"); },
            position: ['middle', 20],
            modal: true,
            dialogClass: 'notitle',
            buttons: {
                save: function () {
                    $(this).dialog("close");
                    $("#formChangeLeadStatus").submit();
                    UpdateElement('"' + $("#selectedelement").val() + '"');
                },
                cancel: function () {
                    $(this).dialog("close");
                }
            }
        });

        $("#changereason").dialog(
        {
            autoOpen: false,
            width: 1300,
            height: 600,
            open: function () { $(".ui-dialog").css("box-shadow", "#000 5px 5px 5px"); },
            position: ['middle', 20],
            modal: true,
            dialogClass: 'notitle',
            buttons: {
                save: function () {
                    $(this).dialog("close");
                    $("#formChangeReason").submit();
                    UpdateReason('"' + $("#selectedelement").val() + '"');
                },
                cancel: function () {
                    $(this).dialog("close");
                    $("#formChangeReason").submit();
                }
            }
        });

        $(".changelead_returnedtoclient").click(function () {
        alert("This lead has been further validated as a good lead ready for you to process and can not be Returned. Thank you.");
        });

        $(".changeleadstatus").click(function () {
            var id = $(this).data("id");
            $("#selectedelement").val($(this).attr("id"));
            $("#changestatus").dialog("open");
            $('#changestatus').html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            var contactURL = '@(Url.Action("ChangeLeadStatus", "Client"))/?id=' + $(this).data("id") + '&element=' + $(this).attr("id") + "&index=";
            $('#changestatus').load(contactURL);
        });

        $(".changeleadreason").click(function () {
            $("#selectedelement").val($(this).attr("id"));
            $("#changereason").dialog("open");
            $('#changereason').html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            var contactURL = '@(Url.Action("ChangeLeadReason", "Client"))/?id=' + $(this).data("id") + "&index=";
            $('#changereason').load(contactURL);
        });

        $(".changeclientnotes").blur(function () {
            $.ajax({
                type: "GET",
                url: '@(Url.Action("UpdateClientNote", "Client"))/?id=' + $(this).data("id") + "&notetext=" + $(this).val()
            });
        });

        function successfunc(data, elementToUpdate) {
            $("#" + elementToUpdate).text(data);
            if(data=="Lead Rejected")
            {
            elementToUpdate="#" + elementToUpdate.replace("flag","reas") ;
            $(elementToUpdate).attr("class","changeleadreason");
            $("#selectedelement").val(elementToUpdate.substring(1));
            $("#changereason").dialog("open");
            $('#changereason').html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            var contactURL = '@(Url.Action("ChangeLeadReason", "Client"))/?id=' + $(elementToUpdate).data("id") + "&index=";
            $('#changereason').load(contactURL);
            }
        }

        function UpdateElement(elementToUpdate)
        {
            var ans=confirm("Status Changed")
            if (ans==true) {
            $.ajax({
                type: "GET",
                url: "@(Url.Action("UpdateElement", "Client"))/?currentElement=" + elementToUpdate.replace(/["]/g, "'"),
                success: function(data){
                successfunc(data, elementToUpdate.replace(/["]/g, ""));
                }
            });
            }
        }

        function UpdateReason(elementToUpdate)
        {
            var ans=confirm("Reason Allocated, Thank You")
            if (ans==true) {
                var ElementUpdate={};
                ElementUpdate.currentElement=elementToUpdate.replace(/["]/g, "'");
                $.getJSON("UpdateReason",ElementUpdate,function(data)
                {
                $("#" + data.elementToUpdate).text(data.theReason);
                $("#" + data.noteToUpdate).text(data.theNote);
                });
            }
        }
    });
</script>

